#include <cmath>
#include "Neuron.h"

namespace fullsail_ai {

	void Neuron::initialize(std::size_t argumentCount, int (*numberGenerator)())
	{
		// TODO: 4
		// Initialize the bias and the weights to random values.
		double RandNum = (double)((double)numberGenerator()/(double)RAND_MAX);
		RandNum -= 0.5;
		bias = RandNum;
		for(unsigned i = 0; i < argumentCount;i++)
		{
			RandNum = (double)((double)numberGenerator()/(double)RAND_MAX);
			RandNum -= 0.5;
			weights.push_back(RandNum);
		}
		RandNum = getBias();
		argumentCount = getWeights().size();
	}

	double Neuron::computeActivationValue(std::vector<double> const& arguments) const
	{
		// TODO: 6
		// Return the neuron's activation value based on the specified arguments.
		double ret = 0.0;
		for(unsigned i = 0; i < getWeights().size();i++)
		{
			ret += arguments[i]*getWeights()[i];
		}
		ret += bias;
		return (1/(1+exp(-ret)));
	}

	void Neuron::adjust(std::vector<double> const& arguments, double valueError,
	                    double learningFactor)
	{
		// TODO: 11
		// Adjust each weight of the neuron, including the bias.
	}
}  // namespace fullsail_ai

